package com.jlect.swebing.ui.client.menu;

import com.jlect.swebing.ui.client.GComponent;
import com.jlect.swebing.ui.client.KeyEvent;
import com.jlect.swebing.ui.client.MouseEvent;
import com.jlect.swebing.ui.client.SelectionController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Implements additional behavior for menu bar component 
 *
 * @author Sergey Kozmin
 * @since 28.11.2007 20:44:30
 */
public class MenuBarSelectionController implements SelectionController {
    private Map viewToComponent = new HashMap();
    private MenuBarItem selectedComp;

    public void addComponent(MenuBarItem item) {
        GComponent component = item.getView();
        component.addMouseListener(this);
        component.addKeyListener(this);
        viewToComponent.put(component, item);
    }

    public void removeComponent(MenuBarItem item) {
        GComponent component = item.getView();
        component.removeMouseListener(this);
        component.removeKeyListener(this);
        viewToComponent.remove(component);
    }

    public void mouseClicked(MouseEvent e) {
        selectedComp.performAction();
        selectedComp.activate();
    }

    public void mousePressed(MouseEvent e) {
        //@todo implement me
    }

    public void mouseReleased(MouseEvent e) {
        //@todo implement me
    }

    public void mouseEntered(MouseEvent e) {
        selectedComp.deActivate();
        selectedComp = (MenuBarItem) viewToComponent.get(e.getSource());
        selectedComp.activate();
    }

    public void mouseExited(MouseEvent e) {
        //@todo implement me
    }

    public List getSelection() {
        return null;  //@todo implement me
    }

    public void keyTyped(KeyEvent e) {
        //@todo implement me
    }

    public void keyPressed(KeyEvent e) {
        //@todo implement me
    }

    public void keyReleased(KeyEvent e) {
        //@todo implement me
    }
}
